package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Comment;

import com.tanhua.server.service.CommentService;

import com.tanhua.server.service.MqMovementService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.http.ResponseEntity;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

import java.util.Map;

@RestController

@RequestMapping("/comment")

public class CommentsController {

    @Autowired
    private CommentService commentService;

    @Autowired
    private MqMovementService mqMovementService;

    @GetMapping(name = "分页查询指定动态的评论列表")
    public ResponseEntity queryComments(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10")Integer pagesize,
                                        String movementId){
        Integer commentType = 2;
        return commentService.queryComments(page,pagesize,movementId,commentType);
    }
    @PostMapping(name = "发布评论")
    public ResponseEntity saveComments(@RequestBody Map param){
        String movementId = (String) param.get("movementId");
        String comment = (String) param.get("comment");
        String commentType = "2";
        Map<String,String> map = new HashMap<>();
        map.put("movementId", movementId);
        map.put("comment", comment);
        map.put("commentType", commentType);
        mqMovementService.sendMgsToMq(movementId,4);
        return commentService.saveComments(map);
    }

}
